<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>书籍类别表</title>
    <link rel="stylesheet" href="http://47.100.102.177:8080/app/css/common/bootstrap.min.css">
    <link rel="stylesheet" href="../../../boot/plugin/download/font_2801350_hw9pyy8c125/iconfont.css">    <script src="http://47.100.102.177:8080/app/js/common/jquery-1.12.4.js"></script>
    <!-- 必须先引入vue，  后使用element-ui -->
    <script src="../../../boot/plugin/element/vue.js"></script>
    <!--引入 element-ui 的样式，-->
    <link rel="stylesheet" href="../../../boot/plugin/element/element.css">
    <!-- 引入element 的组件库-->
    <script src="../../../boot/plugin/element/element.js"></script>
    <style>
        th {
            text-align: center;
        }
        
        .bg-add {
            width: 100%;
            height: 100vh;
            position: absolute;
            top: 0px;
            background-color: rgba(0, 0, 0, 0.2);
            display: none;
        }
        
        .inf {
            background-color: white;
            height: 630px;
            width: 45%;
            margin: auto;
            margin-top: 60px;
            border-radius: 3px;
        }
        
        .inf-head {
            width: 100%;
            height: 30px;
            background-color: rgb(21, 184, 215);
            border-radius: 3px;
        }
        
        #close-add {
            float: right;
            margin-right: 5px;
            background-color: red;
            color: white;
            font-weight: 900;
            border-radius: 5px;
            border: 0px;
            margin-top: 3px;
        }
        
        .inf-from {
            width: 100%;
            height: 600px;
            border-radius: 3px;
            overflow: scroll;
        }
        
        .mailTable {
            width: 100%;
            border-top: 1px solid #E6EAEE;
            border-left: 1px solid #E6EAEE;
            margin-bottom: 30px;
        }
        
        .mailTable tr td {
            width: 200px;
            height: 35px;
            line-height: 35px;
            box-sizing: border-box;
            padding: 0 10px;
            border-bottom: 1px solid #E6EAEE;
            border-right: 1px solid #E6EAEE;
        }
        
        .mailTable tr td.column {
            background-color: #EFF3F6;
            color: #393C3E;
            width: 30%;
        }
    </style>
</head>

<body>
    <div style="width: 100%;height: 20px;"></div>
    <form class="form-inline" style="text-align: center;">
        <div class="form-group">
            <label for="bookTypeName">书籍类别名</label>
            <input type="text" class="form-control" name="categoryName" id="bookTypeName" placeholder="请输入书籍类别名称">
        </div>
        <button type="button" class="btn btn-default" onclick="search_bookType()"><i class="iconfont"
                style="font-size: 14px;color: #3E8EF7;">&#xe660;</i></button>
    </form>
    <div style="width: 100%;height: 20px;"></div>
    <table class="table table-bordered" style="text-align: center;">
        <thead id="th">
            <tr>
                <th>书籍类别id</th>
                <th>书籍类别名称</th>
            </tr>
        </thead>
        <tbody id="tb">

        </tbody>
    </table>
    <div style="float: right;margin-right: 20px;">
        <div style="float: left;height: 80px;line-height: 80px;margin-right: 20px;" id="pageNum">共&nbsp;<span style="color: red">${haveBookCategory}</span>&nbsp;条记录&nbsp;&nbsp;</div>
        <div style="float: left;height: 80px;line-height: 80px;margin-right: 20px;">&nbsp;<span style="color: red">12</span>&nbsp;条&nbsp;/&nbsp;页</div>
        <div id="app" style="float: left;" onclick="page()">
            <el-pagination background layout="prev, pager, next" :total="${allBookCategory}*10" style="margin-top: 23px;">
            </el-pagination>
        </div>
    </div>
    <script>
        new Vue().$mount('#app');
        let book_type = ${bookCategory};

        let pageNum = document.getElementById("pageNum");
        let allBookCategory = ${allBookCategory};
        let haveBookCategory = ${haveBookCategory};

        let tb = document.getElementById("tb");
        let str = "";
        for (let i = 0; i < book_type.length; i++) {
            str += '<tr>';
            str += '<td>' + book_type[i].categoryId + '</td>';
            str += '<td>' + book_type[i].categoryName + '</td>';
            str += '</tr>';
        }
        tb.innerHTML = str;

        function page() {
            str = "";
            let active = document.getElementsByClassName("active")[0];

            let param = "nowPage="+parseInt(active.innerText);
            $.get('/boot/admin/getNowPageOfBookType',param,function (res) {
                book_type = res;
                for (let i = 0; i < book_type.length; i++) {
                    str += '<tr>';
                    str += '<td>' + book_type[i].categoryId + '</td>';
                    str += '<td>' + book_type[i].categoryName + '</td>';
                    str += '</tr>';
                }
                tb.innerHTML = str;
            });
            // 点击返回页码数
            // console.log(active.innerText);
            // alert("当前第" + active.innerText + "页")
            // return parseInt(active.innerText);
        }

        function search_bookType(){
            str = "";
            let categoryName = document.getElementById("bookTypeName").value;
            let param = "categoryName="+categoryName;
            $.get('/boot/admin/searchByBookType',param,function (res){
                book_type = res;
                if (book_type!=null&&book_type.length>0){
                    for (let i = 0; i < book_type.length; i++) {
                        str += '<tr>';
                        str += '<td>' + book_type[i].categoryId + '</td>';
                        str += '<td>' + book_type[i].categoryName + '</td>';
                        str += '</tr>';
                    }
                }else {
                    str += '<tr><td colspan="2">查无此结果</td></tr>';
                }
                tb.innerHTML = str;
            });
        }



    </script>
</body>

</html>